package me.zhengjie.poemQuestions.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.poemQuestions.domain.PoemQuestions;
import me.zhengjie.poemQuestions.service.PoemQuestionsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yellow
 * @date 2025-04-20
 **/
@RestController
@RequestMapping("/api/poem_questions")
@RequiredArgsConstructor
@Api(tags = "诗词题库接口")
public class PoemQuestionsController {

    private final PoemQuestionsService poemQuestionsService;

    @GetMapping("/random")
    @ApiOperation("获取每日随机一题")
    @AnonymousAccess
    public PoemQuestions getRandomQuestion(@RequestParam Integer userId) {
        return poemQuestionsService.getRandomQuestionForUser(userId);
    }

    @Log("根据答题薄弱点推荐题目")
    @ApiOperation("根据答题薄弱点推荐题目")
    @GetMapping("/recommend")
    @AnonymousAccess
    public ResponseEntity<List<PoemQuestions>> recommend(@RequestParam Integer userId,
                                                         @RequestParam(defaultValue = "2") int limitPerCategory,
                                                         @RequestParam(defaultValue = "3") int categoryLimit) {
        return ResponseEntity.ok(poemQuestionsService.recommendWeakQuestions(userId, limitPerCategory, categoryLimit));
    }
}
